@ui_info = %Q[
<ui>
  <menubar name='MenuBar'>
    <menu action='FileMenu'>
      <menuitem action='New'/>
      <menuitem action='Open'/>
      <separator/>
      <menuitem action='Close'/>
      <separator/>
      <menuitem action='Save'/>
      <menuitem action='Save As'/>
      <separator/>
      <menuitem action='Quit'/>
    </menu>
    <menu action='EditMenu'>
      <menuitem action='Undo'/>
      <menuitem action='Redo'/>
      <separator/>
      <menuitem action='Cut'/>
      <menuitem action='Copy'/>
      <menuitem action='Paste'/>
    </menu>
    <menu action='ViewMenu'>
    </menu>
    <menu action='ProgramMenu'>
      <menuitem action='Compile'/>
      <menuitem action='Run'/>
    </menu>
    <menu action='HelpMenu'>
      <menuitem action='About'/>
    </menu>
  </menubar>
  <toolbar  name='ToolBar'>
    <toolitem action='New'/>
    <toolitem action='Open'/>
    <separator action='Sep1'/>
    <toolitem action='Save'/>
    <toolitem action='Save As'/>
    <separator action='Sep2'/>
    <toolitem action='Undo'/>
    <toolitem action='Redo'/>
    <separator action='Sep3'/>
    <toolitem action='Quit'/>
    <separator action='Sep4'/>
  </toolbar>
</ui>]

require 'gtk2'
require 'sEdit'
require 'sFile'
require 'sFileChooser'

# this is a generic callback to capture actions and show whih are in need of implementation
callback = Proc.new {|actiongroup, action| 
  puts "`#{action.name}' is clicked."
  puts "`#{action.name}' is unimplemented. "
  if action.is_a? Gtk::ToggleAction
    puts "active? = #{action.active?}"
  end
}

callback_open = Proc.new {
  p "Open is Called"
  @dialog_type = "Open File"
  file_dialog
  if @filename
    text = read_file
    @buffer.set_text(text)
  end
  @buffer.place_cursor(@buffer.start_iter)
  @sourceview.has_focus = true

}

callback_save_as = Proc.new {
  p "Save As is Called"
  @dialog_type = "Save File As"
  file_dialog
  save_file if @filename
}

callback_quit = Proc.new {
  p "Quit is called."
  Gtk.main_quit
}

callback_save = Proc.new {
  p "Save is Called"
  @dialog_type = "Save File"
  if @filename
    save_file
  else
    callback_save_as
  end
}

callback_new = Proc.new {
  p "New is Called"
  if @buffer.modified?
    callback_save_as
  end
  @filename = nil
  on_clear
}

callback_close = Proc.new {
  p "Close is Called"
  if @buffer.modified?
    callback_save_as
  end
  @filename = nil
  on_clear
}

callback_undo = Proc.new {
  p "Undo is Called"
  on_undo
}

callback_redo = Proc.new {
  p "Redo is Called"
  on_redo
}

callback_cut = Proc.new {
  p "Cut is Called"
  on_cut
}

callback_copy = Proc.new {
  p "Copy is Called"
  on_copy
}

callback_paste = Proc.new {
  p "Paste is Called"
  on_paste
}

@actions = [
  ["FileMenu", nil, "_File"],
  ["EditMenu", nil, "_Edit"],
  ["ViewMenu", nil, "_View"],
  ["ProgramMenu", nil, "_Program"],
  ["HelpMenu", nil, "_Help"],
  ["New", Gtk::Stock::NEW, "_New", "<control>N", "Create a new file", callback_new],
  ["Open", Gtk::Stock::OPEN, "_Open", "<control>O", "Open a file", callback_open],
  ["Close", Gtk::Stock::CLOSE, "_Close", "<control>W", "Close a file", callback_close],
  ["Save", Gtk::Stock::SAVE, "_Save", "<control>S", "Save current file", callback_save],
  ["Save As", Gtk::Stock::SAVE_AS, "Save _As...", nil, "Save to a file", callback_save_as],
  ["Quit", Gtk::Stock::QUIT, "_Quit", "<control>Q", "Quit", callback_quit],
  ["Undo", Gtk::Stock::UNDO , "_Undo", nil, "Undo", callback_undo],
  ["Redo", Gtk::Stock::REDO, "_Redo", nil, "Redo", callback_redo],
  ["Cut", Gtk::Stock::CUT, "_Cut", "<control>X", "Cut", callback_cut],
  ["Copy", Gtk::Stock::COPY, "_Copy", "<control>C", "Copy", callback_copy],
  ["Paste", Gtk::Stock::PASTE, "_Paste", "<control>V", "Paste", callback_paste],
  ["Compile", Gtk::Stock::PASTE, "_Compile", "<control>B", "Compile", callback],
  ["Run", Gtk::Stock::PASTE, "_Run", nil, "Run", callback],
  ["About", nil, "_About", "<control>A", "About", callback]
]


